package servlet;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Calendar;
import connection.DbConnection;

import bean.PollUser;
import bean.Question;

public class feedbackServlet extends HttpServlet {



	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost (request, response);
	}
	
	public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String text = request.getParameter("text");
		HttpSession session=request.getSession(true);
    	PollUser pu = (PollUser)session.getAttribute("user");
    	Calendar calendar = Calendar.getInstance();
    	java.util.Date currentDate = calendar.getTime();
    	java.sql.Date date = new java.sql.Date(currentDate.getTime());
    	
    	// Needs to be used once PollUser page created with Question bean generated
    	Question question = (Question)session.getAttribute("question");
    	String sql = "INSERT INTO Feedback (Text, QuestionId, PollUser) VALUES ('"+text+"','"+question.getQuestionID()+"',"+pu.getUsername()+"')";
    	
    	DbConnection conn = new DbConnection();
    	conn.doInsert(sql);
    	
	}
}
